package com.example.api.controller;

import com.example.api.aspect.SystemControllerLog;
import com.example.api.model.entity.Distribution;
import com.example.api.model.enums.ActionTypeEnum;
import com.example.api.model.support.RespBean;
import com.example.api.service.DistributionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "配送管理")
@RestController
@RequestMapping("/api/distribution")
public class DistributionController {

    @Resource
    private DistributionService distributionService;

    @ApiOperation("添加配送")
    @PostMapping("/")
    @SystemControllerLog(description = "添加配送", actionType = ActionTypeEnum.CREATE)
    public RespBean save(@RequestBody Distribution distribution) throws Exception {
        return distributionService.save(distribution);
    }

    @ApiOperation("查询配送")
    @GetMapping("/")
    @SystemControllerLog(description = "查询配送", actionType = ActionTypeEnum.QUERY)
    public List<Distribution> findAll() {
        return distributionService.findAll();
    }

    @ApiOperation("查询可配送车辆和驾驶员")
    @GetMapping("/can")
    @SystemControllerLog(description = "查询可配送车辆和驾驶员", actionType = ActionTypeEnum.QUERY)
    public Map<String, Object> can() {
        return distributionService.can();
    }

    @ApiOperation("更新配送")
    @PutMapping("/")
    @SystemControllerLog(description = "更新配送", actionType = ActionTypeEnum.UPDATE)
    public RespBean update(@RequestBody Distribution distribution) {
        return distributionService.update(distribution);
    }

    @ApiOperation("更新状态")
    @PutMapping("/status")
    @SystemControllerLog(description = "更新状态", actionType = ActionTypeEnum.UPDATE)
    public RespBean updateStatus(@RequestBody Distribution distribution) {
        return distributionService.updateStatus(distribution);
    }

}